Jump to content

[SOLVED] move_uploaded_file - how to debug?


marmite

Recommended Posts

Hi, this is driving me batty. I have taken code from my original site (which worked great). I tested it on my localhost (also worked fine, after a bit of fiddling).

 

Now I'm trying it live and it ain't working (I have the same directory structure and the same code). I realise no-one can help diagnose the problem from a distance, but does anyone know how to debug it? Find out why it's not working? Really appreciate it ???

 

if ($_POST['upload']) {
$temporary_name=$_FILES['file']['tmp_name'];
        $newpath = "shots/" . $newfilename;
move_uploaded_file($temporary_name, $newpath);
}

Link to comment
Share on other sites

What symptoms are you getting?  Any error messages?

 

The first things I'd check would be filesystem related.  Do you have the correct permissions in the directories?  If the webserver is chrooted, you may need to create the tmp directory.  Those are my first two thoughts.

 

In that snippet, where do you define $newfilename?

Link to comment
Share on other sites

as Wildbug said, error messages would be very useful. that is the reason they exist, so that we can use them to debug the problem.

 

 

 

one thing that could be causing the problem is that your upload limit maybe smaller than the size of the file you are trying to upload. but i'll wait for your reply with the exact errors before i elaborate.

Link to comment
Share on other sites

Sorry, I'm very new to this.

 

Where do I find the error messages?

 

I have access only to my segment of the server. There are some gz logs but they seem to be in Chinese...

 

The tmp directory must exist because it worked before. Plus as you can see from the code below, the name of the file is picked up, wherever it is.

 

The code falls over in the resizeimage function, which I have not posted since the reason it falls over is that the file it is expecting is not where it should be! Hence, I deduce that the move_uploaded_file is not working.

 

Thanks for any help. Still stuck over here!

 

if ($_POST['upload']) {
$time = mktime();
$hash = md5($time);
$mimetype = $_FILES['file']['type']; 
$temporary_name = $_FILES['file']['tmp_name'];
$tmpimage = imagecreatefromjpeg($temporary_name);
$filesize = $_FILES['file']['size'];
$maxsize = 2000000;
if ($mimetype != "image/jpg" and $mimetype != "image/jpeg" and $mimetype != "image/pjpeg") {
$error = "Sorry, your upload was unsuccessful because the file is not a jpg. Please convert the image and resubmit.";
}
if (empty($mimetype) and empty($filesize)) {
$error = "Sorry, your upload was unsuccessful because the file was over 2MB. Please reduce the file size and resubmit.";
} else {
$newfilename = $hash . ".jpg";
$newpath = "shots/" . $newfilename;
move_uploaded_file($temporary_name, $newpath);
        resize_image($newfilename);
$dbfilename = "thumbnail" . $newfilename;

$query = "INSERT INTO shots (shot_author, shot_timestamp, shot_location, shot_name, shot_filename, shot_category) VALUES('$_SESSION[memberid]', '$time', '$_POST[location]', '$_POST[shot_name]', '$dbfilename', '$_POST[category]')";

mysql_query($query) or die("Error in SQL query ".mysql_error());
mysql_query("UPDATE users set images = (images + 1) where user_id = '$_SESSION[memberid]'") or die("Error in query " . mysql_error());

$to = "enquiries@cardsunlimited.com";
$from = "From: GotAShot Submissions <submissions@cardsunlimited.com>\n\r";
$subject = "New GotAShot Submission";

$content = <<<FOE
Hi Emma

Just to let you know that you have received a GotAShot Submission

Best Wishes,
The Cards Unlimited Team
www.cardsunlimited.com
FOE;
mail($to, $subject, $content, $from);

}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.