Using Expression Web, want to upload images to my web pages, not getting error messages even though written in script. Set the upload folder to share with everyone. php.ini
is set to file_uploads=on;upload_max_size=128M
. On firefox the script times out and on IE "Internet Explorer can not display page."
I have been searching for answers for weeks. Every other script I have tried works even though I am a novice at php. This upload thing has gotten me scratching my head. Most recent upload script attempt:
if (isset($_POST['submitted'])) {
// Check for an uploaded file:
if (isset($_FILES['upload'])) {
// Validate the type. Should be JPEG or PNG.
$allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
if (in_array($_FILES['upload']['type'], $allowed)) {
$target_path = "C:/uploads/";
$name=$_FILES['upload']['name'];
$error=$_FILES['upload']['error'];
$tmp_name=$_FIL开发者_运维百科ES['upload']['tmp_name'];
if($error==UPLOAD_ERR_OK){
if($_FILES['upload']['size']>0){
move_uploaded_file($tmp_name, $target_path.$name);
print ("The file ".$name." has been uploaded.\n");
} else{
print ("There was an error uploading the file, please try again!\n");
}
}elseif ($error==UPLOAD_ERR_NO_FILE) {
print("No files specified.\n");
}else{
print("Upload failed.\n");
}
print("\n");
}//End of !in_array IF.
} // End of isset($_FILES['upload']) IF.
} // End of the submitted conditional.
?>
<div>
<form action="photogallery.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
<p><b>File:</b><input name="upload" type="file" /></p>
<input name="submit" type="submit" value="Submit" />
<input name="submitted" type="hidden" value="TRUE" />
</form>
</div>
I am trying to upload images into upload folder in my directory and then display on my web page. I have put images into the folder manually and they will show on my webpage via a link but it wont work using these scripts. My site is not live it is in developement and I am using XAMPP and Microsoft development Server.
The actual error is hard to tell. But there are a few points to mention on your script (typical upload script problems):
- The
['name']
constanct could be empty, which would explain an upload error. - But it could also be tampered with, and contain things like
"../Windows/System.ini"
, which wouldn't be so good for your script since you use it unfiltered as output filename. - The MIME
['type']
is likewise unreliable. But that's likely not the problem here. At the very least usestrtolower()
on it instead of listing multiple MIME alternatives. - Lastly enable
error_reporting(E_ALL);
which will tell you if move_upload_file() permission issues are the problem.
I would suggest that you start with a simple
move_uploaded_file($_FILES["upload"]["tmp_name"], "C:/uploads/test.1");
And then gradually extend it with your other conditions to find the cause of your upload issue.
精彩评论