Jump to content

Upload Image Problem


bravo14
 Share

Recommended Posts

Hi 

 

The code below forms part of another piece of code, but I am having problems uploading an image

 

	// Your file name you are uploading 
$file_name = $logo;

// random 4 digit to add to our file name 
// some people use date and time in stead of random digit 
$random_digit=rand(0000,9999);

//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables

$new_file_name=$random_digit.$file_name;

//set where you want to store files
//in this example we keep file in folder upload 
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "logos/".$new_file_name;
if($logo !=none)
{
if(copy($HTTP_POST_FILES['logo']['tmp_name'], $path))
{
echo "Successful<BR/>"; 

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$new_file_name."<BR/>"; 
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
}
else
{
echo "Error";
}
}

 

The error messages I am getting are

 

Notice: Undefined variable: logo in C:\wamp\www\wedding_buddy\new_supplier.php on line 27

 

Notice: Use of undefined constant none - assumed 'none' in C:\wamp\www\wedding_buddy\new_supplier.php on line 43

 

Notice: Undefined variable: ufile in C:\wamp\www\wedding_buddy\new_supplier.php on line 43

 

Notice: Undefined variable: HTTP_POST_FILES in C:\wamp\www\wedding_buddy\new_supplier.php on line 45

 

Warning: copy() [function.copy]: Filename cannot be empty in C:\wamp\www\wedding_buddy\new_supplier.php on line 45

 

The variable logo is a field from a form, what have I done wrong?

Link to comment
Share on other sites

A) Your code has absolutely no error checking and error reporting logic in it to check if the upload worked before accessing any of the uploaded file information.

 

B) $HTTP_POST_FILES was depreciated a really long time ago (php 4.1, Dec. 2001), turned off by default in php5, and to be removed in the next major php revision. The code should be using $_FILES instead of $HTTP_POST_FILES

 

C) I recommend that you read the upload handling section of the php.net documentation before spending any more of your time on that code.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.