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>
Remove your hidden input (MAX_FILE_SIZE) and it'll work fine...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your current script will only accept files less than 51k (MAX_FILE_SIZE = 51200)
ASKER
I did that but it gave me this warning:
Warning: move_uploaded_file(C:/uplo ad_test/IM G_3535.JPG ) [function.move-uploaded-fi le]: failed to open stream: No such file or directory in /home/content/64/11583764/ html/summe r/test2/up load3.php on line 8
Warning: move_uploaded_file() [function.move-uploaded-fi le]: Unable to move '/tmp/phpkQMxeN' to 'C:/upload_test/IMG_3535.J PG' in /home/content/64/11583764/ html/summe r/test2/up load3.php on line 8
but i created the folder in C:\upload_test
Warning: move_uploaded_file(C:/uplo
Warning: move_uploaded_file() [function.move-uploaded-fi
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.
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.
ASKER
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.
ASKER
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.
ASKER
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
ASKER
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?
//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?