milescook Posted September 28, 2006 Share Posted September 28, 2006 Ok, I'm having no end of trouble trying to upload a file to my server (using CGI and PHP). File limits are fine, as I tried files of only a few kb. Uploads are on. I'm guessing the file is going to the server, and then getting deleted. I tried a df before, during and after the transfer, and that's why I think this.Code is as follows for do_upload[code]<?php $err_upload = ""; $image_file = $_FILES[’upload_file’];$temporary_name = $image_file[’tmp_name’]; if (is_uploaded_file($temporary_name)) { // get image information $image_metadata = getimagesize($temporary_name); if ($image_metadata) { $image_width = $image_metadata[0]; $image_height = $image_metadata[1]; $image_type = $image_metadata[2]; $save_name = $temporary_name; switch ($image_type) { case IMAGETYPE_GIF: $save_name .= ".gif"; break; case IMAGETYPE_PNG: $save_name .= ".png"; break; default: $err_upload = "Sorry… we only allow gif and png images."; break; } if (! $err_upload) { if (move_uploaded_file($tmp_name, "uploads/file")) { // you might update a database with key information here so // that the image can be used later } else { $err_upload = "Sorry… something went horribly awry."; } } } } else { // some error occurred: handle it switch ($image_file[’error’]) { case 1: // file too big (based on php.ini) case 2: // file too big (based on MAX_FILE_SIZE) $err_upload = "Sorry… image too big."; break; case 3: // file only partially uploaded case 4: // no file was uploaded case 6: // missing a temporary folder case 7: // failed to write to disk (only in PHP 5.1+) $err_upload = "Sorry… failed to upload… problem with server."; break; }} if ($err_upload) { print $err_upload;} else { print "Success!!!";}?> [/code]I have carried out the recommendations, and I have turned on error reporting. I get this:[code]Notice: Use of undefined constant �upload_file� - assumed '�upload_file�' in /usr/local/apache2/html/do_upload.php on line 5Notice: Undefined index: �upload_file� in /usr/local/apache2/html/do_upload.php on line 5Notice: Use of undefined constant �tmp_name� - assumed '�tmp_name�' in /usr/local/apache2/html/do_upload.php on line 6Notice: Use of undefined constant �error� - assumed '�error�' in /usr/local/apache2/html/do_upload.php on line 46Success!!![/code]My phpinfo is at http://apollo.cookieonline.net/phpinfo.phpPage is at http://apollo.cookieonline.net/upload_file.htmlIt says success, but the file is not in uploads!!Please help! Link to comment https://forums.phpfreaks.com/topic/22371-upload-file-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.