bravo14 Posted October 18, 2010 Share Posted October 18, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/216192-upload-image-problem/ Share on other sites More sharing options...
bravo14 Posted October 19, 2010 Author Share Posted October 19, 2010 The data is added to the database, except for the filename, it picks up the randomdigit, just not the filename Quote Link to comment https://forums.phpfreaks.com/topic/216192-upload-image-problem/#findComment-1123997 Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2010 Share Posted October 19, 2010 does $logo have a value?? if not, then neither does $file_name. $file_name = $logo; Quote Link to comment https://forums.phpfreaks.com/topic/216192-upload-image-problem/#findComment-1124017 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216192-upload-image-problem/#findComment-1124027 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.