IronWarrior Posted August 23, 2008 Share Posted August 23, 2008 Have this so far, no errors, it just does nothing, doesnt echo OR create a new directory... //If all fields have been completed, then continue. else { // Checking if an image has been uploaded if (is_uploaded_file($imgfile)) { // Checking if a directory already exists for the file if (is_dir($trimmedVehicleName)== false) { // Creating a directory if the directory does not exist echo "Directory does not exist"; mkdir($trimmedVehicleName); } //Copying the file to the directory if (!copy($imgfile, $newName)) { print "Error Uploading File."; exit(); } } } Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2008 Share Posted August 23, 2008 There is really no way to help you based on that small section of code. For example, where is $imgfile getting set? Is your code checking for upload errors? What have you done to troubleshoot this? Have you echoed (using print_r()) out the $_FILES array to see what it contains? Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623721 Share on other sites More sharing options...
IronWarrior Posted August 23, 2008 Author Share Posted August 23, 2008 Sorry, here is the form code: <h3> List an item </h3> <p> This is the section of the website where you can list a new item for sale. </p> <form action="index.php?page=submitAnItem" enctype="multipart/form-data" method="post"> Vehicle Name: <input type="text" name="vehicleName" size="35"> <br /> Vehicle Description: <textarea name="vehicleDescription" cols="60" rows="30"></textarea> <br /> Vehicle Price <input type="text" name="vehiclePrice"> <br /> Vehicle Type <input type="text" name="vehicleType"> <br /> Vehicle Category <br /> <input type="radio" name="vehicleCategory" value="1"> Armoured Vehicle <br /> <input type="radio" name="vehicleCategory" value="2"> Truck <br /> <input type="radio" name="vehicleCategory" value="3"> Jeep <br /> Upload Images: <br /> <input type="hidden" name="MAX_FILE_SIZE" value="3000000"> <input type="file" name="imgfile"> <br /> <input type="file" name="file[]"> <br /> <input type="file" name="file[]"> <br /> <input type="file" name="file[]"> <br /> <input type="hidden" name="validTransaction" value="true"> <input type="submit" value="Submit Listing"> </form> Here is the complete PHP code: <?php if (isset($_POST["validTransaction"])) { $vehicleName = $_POST["vehicleName"]; $vehicleDescription = $_POST["vehicleDescription"]; $vehiclePrice = $_POST["vehiclePrice"]; $vehicleType = $_POST["vehicleType"]; $vehicleCategory = $_POST["vehicleCategory"]; $trimmedVehicleName = str_replace(" ","",$vehicleName); $folderLocation = "images/".$trimmedVehicleName; $currentTime = time(); $newName = $folderLocation."/".$currentTime.$trimmedVehicleName.".jpg"; //Checking if all fields are present if ($vehicleName == "" || $vehicleDescription == "" || $vehiclePrice == "" || $vehicleType == "" || $vehicleCategory == "") { echo "Not all infomation has been completed, please use the return button to re-submit the infomation"; $error = true; } //If all fields have been completed, then continue. else { // Checking if an image has been uploaded if (is_uploaded_file($imgfile)) { // Checking if a directory already exists for the file if (is_dir($trimmedVehicleName)== false) { // Creating a directory if the directory does not exist echo "Directory does not exist"; mkdir($trimmedVehicleName); } //Copying the file to the directory if (!copy($imgfile, $newName)) { print "Error Uploading File."; exit(); } } } } else { echo "Invalid Transaction"; } ?> Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623733 Share on other sites More sharing options...
IronWarrior Posted August 23, 2008 Author Share Posted August 23, 2008 For some strange reason I wasnt allowed to edit my post; so I did a print_r on the $_FILES: Array ( [imgfile] => Array ( [name] => Web_T55_AM2_Qtr_Front2.jpg [type] => image/jpeg [tmp_name] => C:\Windows\Temp\php61BA.tmp [error] => 0 => 43235 ) ) Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623751 Share on other sites More sharing options...
IronWarrior Posted August 23, 2008 Author Share Posted August 23, 2008 Again not allowed to edit previous post so: I have been trouble shooting the problem and it lies with : if (is_uploaded_file($imgfile)) This must be returning false, but why? Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623754 Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2008 Share Posted August 23, 2008 If the variable $_FILES['imgfile']['tmp_name'] contains C:\Windows\Temp\php61BA.tmp (the temporary uploaded file), would if (is_uploaded_file($imgfile)) be checking the correct variable? Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623763 Share on other sites More sharing options...
IronWarrior Posted August 23, 2008 Author Share Posted August 23, 2008 Ahah, so $_FILES['imgfile'] rather than $imgfile ? Link to comment https://forums.phpfreaks.com/topic/120993-solved-having-problems-with-uploading-an-image/#findComment-623767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.