mikemotorcade
-
Posts
4 -
Joined
-
Last visited
Never
Posts posted by mikemotorcade
-
-
Ok, so here is the latest version I have that isn't working:
html form:
[code]<FORM ENCTYPE="multipart/form-data" ACTION="upload.php" METHOD="post" name="upload" id="upload">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="2000000">
<B>Image:</B><BR>
<INPUT TYPE="file" id="image" name="image" VALUE="" SIZE="60" MAXLENGTH="100"><BR>
<BR>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Upload Image">
</FORM>[/code]
upload.php:
[code]
$error = '';
//test for error
if ($_FILES['image']['error'] > 0) {
switch ($_FILES['image']['error']) {
case 1: $error = 'Error[1]: Size exeeded maximum file size allowed.<BR><BR><BR>';
case 2: $error = 'Error[2]: Size exeeded maximum file size allowed.<BR><BR><BR>';
case 3: $error = 'Error[3]: File only partially uploaded<BR><BR><BR>';
case 4: $error = 'Error[4]: No file uploaded<BR><BR><BR>';
}
}
if ($error == '') {
$upfile = '/images/'.$_FILES['image']['name'];
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
if (!move_uploaded_file($_FILES['image']['tmp_name'], $upfile)) {
$error = 'Error: Couldn\'t move file to destination directory<BR><BR><BR>';
}
}else{
$error = 'Error: Image not uploaded';
}
}
if ($error == '') {
echo '<IMG SRC="'.$DOCUMENT_ROOT.'/images/'.$_FILES['file']['name'].'"><BR>';
echo "<B>FILE UPLOADED:</B><BR><BR><HR><I>\"$_FILES['file']['name']\" successfully uploaded<BR></I><HR><BR><BR>\n";
echo '<A HREF="eventimages.php">Add Another Image</A><BR>';
}else{
echo $error;
}
[/code]
Does the directory exist?
yes
Have you set the correct directory permissions?
I chmodded the images dir 777
Did you read my other post of the link provided?
yeah, see below
Have you checked php.ini settings?
Ummm, How do I go about doing that? I was thinking maybe I might have allow upload set to false. I don't know I didn't setup php. I'm using cPanel if that means anything.. it already has everything installed on it, and I don't even know how to access the php.ini file. I don't even know if I can. ???
What server are you using?
linux
What version of PHP are you using?
4.4.1 -
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Check $_FILES['imagefile']['error'] to see if there's a problem first. You could check and use is_uploaded_file() before using move_uploaded_file() (why copy?).[/quote]
Same thing happens with move_uploaded_file(). copy just happened to be what I was trying to use when I gave up.
And I checked. there aren't any errors. My old code I was using contained this:
[code]if ($_FILES['imagefile']['error'] > 0) { continue with code... }[/code]
and
[code]if (is_uploaded_file($_FILES['imagefile']['tmp_name'])) { continue with code... }[/code]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]have u tried to assign a variable for "files/".$_FILES['imagefile']['name'] ?[/quote]
I just did that. It didn't work.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You have to be very careful when allowing uploading of files for security reasons.[/quote]
Yeah, I know. I had a lot more code than just that line. But I determined that it was the phase where I copy the image to a new location that it fails, so I just posted that line.
-
I need help. Why doesn't this work?
[code]copy($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) or die ("Could not copy"); [/code]
I'm trying to upload images and this line NEVER works.
I can't upload an image
in PHP Coding Help
Posted
I ended up changing the path variable from
[code]$upfile = '/images/'.$_FILES['image']['name'];[/code]
to
[code]$upfile = $_SERVER['DOCUMENT_ROOT'].'/images/'.$_FILES['image']['name'];[/code]
and it worked.
So I don't really know exactly what my problem was, but it works now. Thanks for all your help. I really appreciate it.
-Michael