Jump to content

Image Upload Failure


anthonydamasco

Recommended Posts

I have a script that I've been messing with and I am having trouble setting a path for images, I'm getting an upload failed response

 

on the webserver the path is www/OEM/admin/thumbs

 

the php page is located in the "admin" folder

 

Ive tried both paths, I think I'm messing something up.

 

<form action="add.php" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="userfile">
</form>

 

<?php

$path = "/thumbs/";

$max_size = 2000000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>n"; exit; }

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>n"; exit; } else { echo "upload sucessful<br>n"; }

echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>n";
} else { echo "Wrong file type<br>n"; exit; }
}


$my_file = $HTTP_POST_FILES['userfile']['name'];

?>

 

ERROR "upload failed!"

 

Any one have ideas?

Link to comment
https://forums.phpfreaks.com/topic/40769-image-upload-failure/
Share on other sites

try uploading a file (test1.txt) to the absolute path of "/thumbs/" and try the code below.

<?php
$path = "/thumbs/"; #<-- change to absolute path 
$avar1 = "test1.txt";
$avar2 = "test2.txt";

echo copy($path.$avar1, $path.$avar2);
?> 

 

 

 

.. nice snippet bwochinski :)

Link to comment
https://forums.phpfreaks.com/topic/40769-image-upload-failure/#findComment-197388
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.