PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have just transfered my webpage to another server, and now the script that uploads an image file doesnt work. All i get is the "Sorry, there was a problem uploading your file." from when the image fails to trasfer.
$rand1 = rand();
$target = dirname( __FILE__ )."photos/";
$target1 = $target . $rand1 . basename( $_FILES['photo1']['name']);
if (($_FILES['photo1']['name']) == ""){
$pic1="default.gif";
}
else{
$pic1 = $rand1 . basename( $_FILES['photo1']['name']);
if (!getimagesize($_FILES['photo1']['tmp_name'])){
echo "Invalid Image File...";
exit();
}
}
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$address = $_REQUEST['address'];
$lat = $_REQUEST['lat'];
$lng = $_REQUEST['lng'];
$date=time();
if (($_FILES['photo1']['name']) != ""){
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target1))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
//create thumbanail
$n_width=100; // thumbanil width
$n_height=100; // thumbnail height
$thumbs = "thumbnails/";
$thumbs = $thumbs . $rand1 . basename( $_FILES['photo1']['name']);
//if($_FILES['photo1'][type]=="image/jpeg"){
$im=ImageCreateFromJPEG($target1);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$thumbs);
//chmod("$thumbs",0777);
//}
// end thumbnail creation
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}
try to echo $_FILES['error'] in the error reporting statement (sorry the file could not be uploaded) and try to look for the error codec that corresponds to the error.
Mostly the permissions problem
Thanks for tou answer, i did what you said and i got value 0 from it, which from php manual means "There is no error, the file uploaded with success". The error is printed when the file is being moved to the directory i want, which fails.
I think it might be a permissions error, but when i try to chmod 777 the folder where it gets uploaded from filezilla, i get a command not understood.
Command: SITE CHMOD 777 photos
Response: 500 'SITE CHMOD 777 photos': command not understood
Should i contact the administrator for this, or is there another way around ?
If your file is located at "/gallery/index.php", $target will be "/galleryphotos/". If you want it to be "/gallery/photos/", you need to change line 3 to
If your file is located at "/gallery/index.php", $target will be "/galleryphotos/". If you want it to be "/gallery/photos/", you need to change line 3 to
Made the change, but still no luck. I added dirname( __FILE__ ) when i was trying to fix the problem. It still cant move the uploaded file to my directory.