PHP File Upload Script is not writing to temp directory -


alright, having issue image uploading script/application. have tried debugging time after time again , still cannot find out issue is. code seems fine, reason or file looks it's not saved in temp directory can moved on uploads directory on server. have made directory(uploads) i'm trying upload to, including temp directory, have read/write/execute permissions set , uploads set on in php.ini folder. have feeling files never getting saved temp folder, i'm not sure how check if case, since understand file deleted after script finishes executing. hope guys can me out, because have no clue do. there's code script.

also, issue located at.

if (is_uploaded_file($filetempname)) {           $final = "../public_html/uploads/" . $filename;                         $result = move_uploaded_file($filetempname, $final);           if($result)           {             echo 'success';             echo "<br>stored in: " . "public_html/uploads/" . $filename;           }           else           {             echo 'image not uploaded.';           } 

$result= move_uploaded_file($filetempname, $final) keeps returning false no sign of error occuring. know if file type not correct it'll return false , won't copy , it'll return false if file cannot moved reason , raise alert message saying that. however, i'm not having message raised @ all. know returns false , doesn't should do.

<?php error_reporting(e_all); print_r($_files); $filetype = $_files["file"]["type"]; $filename = $_files["file"]["name"]; $filetempname = $_files["file"]["tmp_name"]; $filesize = $_files["file"]["size"]; $error = $_files["file"]["error"];  $allowedexts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $filename)); if ((($filetype == "image/gif") || ($filetype == "image/jpeg") || ($filetype == "image/jpg") || ($filetype == "image/pjepg") || ($filetype == "image/x-png") || ($filetype == "image/png")) && ($filesize < 1000000) && in_array($extension, $allowedexts)) {     if ( $error > 0) {         echo "error: " . $error . "<br>";     }     else {         echo "upload: " . $filename . "<br>";         echo "type: " . $filetype . "<br>";         echo "size: " . ($filesize / 1024) . " kb<br>";         echo "stored in: " . $filetempname . "<br>";          if (file_exists("../public_html/uploads/" . $filename)) {             echo $filename . " exists. ";         }                 else {             if (is_uploaded_file($filetempname)) {               $final = "../public_html/uploads/" . $filename;                             $result = move_uploaded_file($filetempname, $final);               if($result)               {                 echo 'success';                 echo "<br>stored in: " . "public_html/uploads/" . $filename;               }               else               {                 echo 'image not uploaded.';               }             }         }     } } else {     echo "invalid file"; } ?> 

here's code form.

<form enctype="multipart/form-data" method="post" action="scripts/snap.php">         <!--<p>             <input id="plat" class="plat" name="plat" type="hidden" value="" />             <input id="plon" class="plon" name="plon" type="hidden" value=""  />         </p>-->         <div class="row">             <label for="file">select image upload</label><br />             <input type="file" name="file" id="file" /><!--onchange="fileselected();"-->          </div>         <div id="filename"></div>         <div id="filesize"></div>             <div id="filetype"></div>         <div class="row">             <input type="submit" name="submit" value="submit" />             <!--<input type="button" onclick="uploadfile()" value="upload" />-->         </div>         <div id="progressnumber"></div>     </form> 

forget file type checking , whatever else. write separate script has 1 responsibility: moving uploaded file place want permanently store it. focus on one little part , working.

once have file-moving code working, wrap in function , then, once part working, integrate file-moving code rest of have.

the overall lesson here that, when come across problem, it's have written code in modular enough way it's quick , easy tell where, exactly, problem is.

also, consider using framework or library handles file uploading work you, because you're kind of reinventing wheel here.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -