Link to home
Start Free TrialLog in
Avatar of imagekrazy
imagekrazy

asked on

Basic file upload is not working that i created.

Created a basic file upload in php, but  it didn't put the image into the folder I created in  the C directory

<?php
// set the maximum upload size in bytes
$max = 51200;
if (isset($_POST['upload'])) {
  // define the path to the upload folder
  $destination = 'C:/upload_test/';
  // move the file to the upload folder and rename it
  move_uploaded_file($_FILES['image']['tmp_name'], $destination . $_FILES['image']['name']);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8">
<title>Upload File</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" id="uploadImage">
  <p>
    <label for="image">Upload image:</label>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
    <input type="file" name="image" id="image">
  </p>
  <p>
    <input type="submit" name="upload" id="upload" value="Upload">
  </p>
</form>
</body>
</html>

Open in new window

Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Remove your hidden input (MAX_FILE_SIZE) and it'll work fine...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your current script will only accept files less than 51k (MAX_FILE_SIZE = 51200)
Avatar of imagekrazy
imagekrazy

ASKER

I did that but it gave me this warning:

Warning: move_uploaded_file(C:/upload_test/IMG_3535.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/64/11583764/html/summer/test2/upload3.php on line 8

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpkQMxeN' to 'C:/upload_test/IMG_3535.JPG' in /home/content/64/11583764/html/summer/test2/upload3.php on line 8

but i created the folder in C:\upload_test
See lines 68-69 in my script.  That gives me the file name.

See lines 76-83.  That gives me the full server path name.

The handy thing about creating a string variable is that you can print it out with var_dump() and see if it contains what you think it should contain.  

My guess is that move_uploaded_file() is trying to do its work relative to its current working directory.  If C:/upload_test is above the WWW root, you might want to rethink that strategy and move the file to something that will have the right permissions.
Wow Ray, your script kicks ass!, in your script I change the file ext to JPG and GIF,and it worked!!, but my question is,I created the  folder (upload_test)  but in your script it sated to click the link to see the image an it shows the image,but  i went to look for the image with out  the link, but i couldn't find it, any suggestion will be help.
Boy I am stupid, I found the file, it wasn't on my local computer it was on my server:)
Try printing out the value of $my_path and see if you can find the image there.
Again thank you!!
wasn't on my local computer...
Ha!  I've done that before, too.  Thanks for the points and best of luck with your project, ~Ray
Ray final question, I applied your script into my page with the css, but when i open the file ,this is what i see:

//CREATE THE FORM FOR INPUT (USING HEREDOC SYNTAX) $form = <<Upload one file
Find a file to Upload ($f_exts):

did I not close  tag or something?