programguru Posted January 30, 2009 Share Posted January 30, 2009 for some reason, after many trials and tests, i am unable to upload an image with the following simple script: HTML <input type="file" name="image" size="35" maxlength="100" /> PHP copy($_FILES[image][temp_name], "c:/www/mttestdir/".$_FILES[image][name]) or die("The file could not be copied"); my php settings are as follows: file_uploads On On upload_max_filesize 32M upload_tmp_dir C:\www\tmp Image is jpg, and well under 32M. I cannot get past my die error! SOS Link to comment https://forums.phpfreaks.com/topic/143181-solved-image-upload-w-xampp-on-windows-w-php5/ Share on other sites More sharing options...
genericnumber1 Posted January 30, 2009 Share Posted January 30, 2009 Read this: http://us3.php.net/manual/en/features.file-upload.post-method.php And are you sure your form is enctype="multipart/form-data"? Link to comment https://forums.phpfreaks.com/topic/143181-solved-image-upload-w-xampp-on-windows-w-php5/#findComment-750958 Share on other sites More sharing options...
NorthWestSimulations Posted January 30, 2009 Share Posted January 30, 2009 Quick Script: Upload.php <?php $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . '/_uploaded/'; $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php'; $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload2.php'; $fieldname = 'file'; $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached'); isset($_POST['submit']) or error('the upload form is needed', $uploadForm); ($_FILES[$fieldname]['error'] == 0) or error($errors[$_FILES[$fieldname]['error']], $uploadForm); @is_uploaded_file($_FILES[$fieldname]['tmp_name']) or error('not an HTTP upload', $uploadForm); @getimagesize($_FILES[$fieldname]['tmp_name']) or error('only image uploads are allowed', $uploadForm); $now = time(); while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) { $now++; } move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename.$fileext) or error('receiving directory insuffiecient permission', $uploadForm); header('Location: ' . $uploadSuccess); function error($error, $location, $seconds = 5) { header("Refresh: $seconds; URL=\"$location\""); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n". '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n". '<html lang="en">'."\n". ' <head>'."\n". ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n". ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n". ' <title>Upload error</title>'."\n\n". ' </head>'."\n\n". ' <body>'."\n\n". ' <div id="Upload">'."\n\n". ' <h1>Upload failure</h1>'."\n\n". ' <p>An error has occured: '."\n\n". ' <span class="red">' . $error . '...</span>'."\n\n". ' The upload form is reloading</p>'."\n\n". ' </div>'."\n\n". '</html>'; exit; } ?> Upload2.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <title>Successful upload</title> </head> <body> <div id="Upload"> <h1>File upload</h1> <p>Congratulations! Your file upload was successful</p> </div> </body> </html> index.php <?php $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.php'; $max_file_size = 30000; ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <title>Upload form</title> </head> <body> <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post"> <h1> Upload form </h1> <p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> </p> <p> <label for="file">File to upload:</label> <input id="file" type="file" name="file"> </p> <p> <label for="submit">Press to...</label> <input id="submit" type="submit" name="submit" value="Upload me!"> </p> </form> </body> </html> This script is great. I use it all the time for minimul security uploads. They will save files in directory "/_uploaded/" Link to comment https://forums.phpfreaks.com/topic/143181-solved-image-upload-w-xampp-on-windows-w-php5/#findComment-750959 Share on other sites More sharing options...
programguru Posted January 31, 2009 Author Share Posted January 31, 2009 Read this: http://us3.php.net/manual/en/features.file-upload.post-method.php And are you sure your form is enctype="multipart/form-data"? yes had the correct multipart, and i was able to get it resolved with the link you sent.. thanks mucho! Link to comment https://forums.phpfreaks.com/topic/143181-solved-image-upload-w-xampp-on-windows-w-php5/#findComment-751149 Share on other sites More sharing options...
programguru Posted January 31, 2009 Author Share Posted January 31, 2009 NorthWestSimulations, Thanks for the helpful code. I decided to use a much parred down version, but it's interesting to see all of the options. Link to comment https://forums.phpfreaks.com/topic/143181-solved-image-upload-w-xampp-on-windows-w-php5/#findComment-751151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.