upload file doesn't work

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!

Moderator: General Moderators

Post Reply
hlynnt
Forum Newbie
Posts: 2
Joined: Tue Jul 07, 2009 10:56 pm

upload file doesn't work

Post 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
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: upload file doesn't work

Post 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
hlynnt
Forum Newbie
Posts: 2
Joined: Tue Jul 07, 2009 10:56 pm

Re: upload file doesn't work

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: upload file doesn't work

Post by Skara »

You can track the errors (and should) yourself:
http://www.php.net/manual/en/features.f ... errors.php
Post Reply