Search the Community
Showing results for tags 'move_uploaded_file'.
-
move_uploaded_file not giving error but not moving file
davidannis posted a topic in PHP Coding Help
I have a script that uploads files fine on my local server running MAMP but when I upload it I get no file upload. I have tried to simplify as much as possible to troubleshoot and came up with the following script: <?php ini_set('display_errors', 1); error_reporting(E_ALL); define('BASE_DIR', '/home/lineligh/public_html/Art3/'); define('IMG_UPLOAD_DIR',BASE_DIR.'artwork/'); $id='4'; print_r($_FILES); if (isset($_FILES['picture']['name'])) { //check size if ($_FILES['picture']['size'] > 900000) { $uploaderr = true; $uploaderrmsg.='File must be less than 900,000 bytes<br />'; } //check type if ($_FILES['picture']['type'] != "image/jpeg" && $_FILES['picture']['type'] != "image/png") { $uploaderr = true; $uploaderrmsg.='File must be a jpeg or png<br />'; } $uploaddir = IMG_UPLOAD_DIR; $uploadfile = $uploaddir . $id . '.' . end((explode(".", $_FILES["picture"]["name"]))); $result = move_uploaded_file($_FILES['picture']['tmp_name'], $uploadfile); echo '<br>'.$_FILES['picture']['tmp_name']."</br>"; echo $uploadfile; echo '<br>$result: '.$result; } ?> Which produces the following output: Array ( [picture] => Array ( [name] => Olivia-IMG_8678.jpg [type] => image/jpeg [tmp_name] => /tmp/phpe5Vpyq [error] => 0 [size] => 192649 ) ) /tmp/phpe5Vpyq /home/lineligh/public_html/Art3/artwork/4.jpg $result: 1 So, the file gets to the server, the move_uploaded_file function claims that it successfully renames the file and puts it in /home/lineligh/public_html/Art3/artwork/ but if I look for the file it is not there. I'm stumped as to what else to check. Webhosting company swears that my permissions are correct. -
I'm trying to test error conditions for file uploads, but when a file intentionally fails, I'm not even sure how to access the code. Here's a snippet: $file_arr = $_FILES[ 'digifile' ]; $fn = $file_arr[ 'name' ]; $temp = $file_arr[ 'tmp_name' ]; $error = $file_arr[ 'error' ]; error_log( 'the error is: ' . $error ); // ** SEE NOTE BELOW if ( $error > 0 ) { $ui->upload_message = "Error during file upload. "; // try to switch the error to show a relevant message } else { if ( move_uploaded_file( $temp, $full_path ) ) // something } My test for now is simple... test a small image file, it's fine. But I have set my max file size to 16MB in php.ini, and I'm intentionally uploading a 19MB file. What is the expected result? Well I can tell you that the result is this code IS NOT REACHED AT ALL! How is that possible? error_log() doesn't get reached. I don't really know what happens when there is an error, but I'd like to show a customer a relevant message if this happened in the real world. There's no boolean result of move_uploaded_file, either, since like I said THE CODE ISN'T REACHED. I really don't understand. Any help is appreciated.
- 4 replies
-
- php
- move_uploaded_file
-
(and 1 more)
Tagged with:
-
<p><p>HI I am having trouble using this function, I am hosting my website on 1and1 with the following php.ini: register_globals = 0 allow_url_fopen = 1 session.bug_compat_warn = 0 memory_limit = 128M max_execution_time=3600 post_max_size = 128M upload_max_filesize= 128M upload_tmp_dir = '/temp' And this is the code used to upload the file: <?php include ('connection.php'); session_start(); $target = "Images/"; $pic=$HTTP_POST_FILES['previewImage']['tmp_name']; $destination='/Images'; $date = date('d-m-Y'); $postarticle = "INSERT INTO articles VALUES (NULL,'$_POST[title]',CURDATE(), '{$_SESSION['ID']}','Images/$_POST[previewImage]', '$_POST[preview]', '$_POST[video]', '$_POST[content]', '$_POST[additionalInformation]', '$_POST[type]')"; if (mysql_query($postarticle,$conn)){ move_uploaded_file($pic,$destination.$HTTP_POST_FILES['previewImage']['name']); header("Location: index.php"); } else { header("Location: {$_SERVER['HTTP_REFERER']}"); } ?>