Page 1 of 1

upload file doesn't work

Posted: Tue Jul 07, 2009 10:59 pm
by hlynnt
I am new to using PHP, been learning it for the past two months. I am not sure why this isn't working. Can anyone help? I'd really appreciate it.

Code: Select all

<?php 
if (array_key_exists('upload', $_POST)) {
  // define constant for upload folder
  define('UPLOAD_DIR', '/public_html/pages/rapid_quote/uploads');
  // replace any spaces in original filename with underscores
  // at the same time, assign to a simpler variable
  $file = str_replace(' ', '_', $_FILES['uploadedfile']['name']);
 
    // move the file to the upload folder and rename it using date stamp
    ini_set('date.timezone', 'America/Los_Angeles');
    $now = date('Y-m-d-His');
    $success = move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
    UPLOAD_DIR.$now.$file);
    "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
      ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
<title>Untitled Document</title>
</head>
 
<body>
 
</p>
    <form action="" method="post" enctype="multipart/form-data" name="uploadModel" id="uploadModel">
      <p>
        <label for="image">Upload model:</label>
        <input type="file" name="uploadedfile" id="uploadedfile" />
      </p>
    <p>
      <input name="send" id="send" type="submit" value="Send message" />
    </p>
    </form>
</body>
</html>
 
Thanks

Re: upload file doesn't work

Posted: Tue Jul 07, 2009 11:04 pm
by Skara
well right off the bat, you're 14th line doesn't have a statement. It's just quoted text.

Code: Select all

"Stored in: " . "upload/" . $_FILES["file"]["name"];
// =>
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
Also, I think... (haven't done this in a while) you need to use basename() on the original name.

Code: Select all

$file = str_replace(' ', '_', basename($_FILES['uploadedfile']['name']));
I could be wrong about the placement of that.

More importantly, why is it "not working?" What error message(s) are you getting?
more info: http://php.net/manual/en/features.file-upload.php

Re: upload file doesn't work

Posted: Tue Jul 07, 2009 11:09 pm
by hlynnt
Thank you I'll try those things,

I'm not actually getting an error message. But the file that I'm trying to upload isn't appearing in the uploads folder.

Re: upload file doesn't work

Posted: Wed Jul 08, 2009 12:37 pm
by Skara
You can track the errors (and should) yourself:
http://www.php.net/manual/en/features.f ... errors.php