Forums

PHP

This topic is locked

Any thoughts?

Posted 01 Jun 2007 14:34:40
1
has voted
01 Jun 2007 14:34:40 Steve W posted:
I am using the script below to upload images and all is working ok with GIF files but when I try and upload JPGs a file appears on the server but when I try and view it, all I get is the red x showing that it cannot display. When I upload, it states that the file type is PJPEG..? I can upload the same files via FTP and they work so it isn't a blocked file type.

Is there anything I need to do in the code below?

Help!!

Cheers, Dub

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES. In PHP versions earlier than 4.0.3, use copy() and
// is_uploaded_file() instead of move_uploaded_file.
$ftp_server = "XXXXXXXX";
$ftp_user = "XXXXXXXX";
$ftp_pass = "XXXXXXXX";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server";

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}

// set folder location on server
$uploaddir = '/XXXXXXXX/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$remote_file = $_FILES['userfile']['name'];;

//I used these for debugging
echo $_FILES['userfile']['name'];
echo "<br>";
echo $_FILES['userfile']['type'];
echo "<br>";
echo $_FILES['userfile']['size'];
echo "<br>";
echo $_FILES['userfile']['tmp_name'], $uploadfile;
echo "<br>";
echo $_FILES['userfile']['error'];
echo "<br>";

//v important this one as you have to use the tmp_file created for the actual upload
$file = $_FILES['userfile']['tmp_name'];
if (ftp_put($conn_id, "$uploadfile" , $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

<html>
<head>
<title>Register</title>

<?php include("includes/menu.php"; ?>
<form enctype="multipart/form-data" action="upload2.php" name="uploadfile" method="post"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /><br>
Send this file: <input name="userfile" type="file" /><br>
<input type="submit" value="Send File" /><br>
</form>
</td>
</tr>
</table>
</body>
</html>

Replies

Replied 01 Jun 2007 16:45:57
01 Jun 2007 16:45:57 Steve W replied:
By the way, the jpeg files I am uploading are not pjpegs!!

Reply to this topic