amwd07 Posted February 11, 2008 Share Posted February 11, 2008 Hi I wander if someone here can help I have downloaded this script from here http://digitarald.de/playground/uploader.html the developer says I need my own upload script so i have tried to use the following which seems to come up with Invalid file all the time. the uploads directory does exist with 777 permissions anyone any idea's? <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "application/pdf") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/ Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 Never use the "||" statement, because it will never come out true. Try <?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] < 20000)){code] ?> You can keep adding to the array Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464341 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 I have now tried the following still the same error <?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("./uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464349 Share on other sites More sharing options...
kishanforum Posted February 11, 2008 Share Posted February 11, 2008 first try to echo the _files['file']['type'] i thnk its not exactly what you are checking... Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464353 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 I have now tried the following still the same error <?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("./uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> The file can be a Pjpeg or something your not expecting. Echo the File Type as Said by KishanForum. Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464357 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 I have tried that echo $file_types and it comes up with ArrayInvalid file Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464362 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 I have tried that echo $file_types and it comes up with ArrayInvalid file $file_types is just an array with text of the allowed filetypes. use <?php echo $_FILES['file']['type']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464364 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 now it just shows Invalid file Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464368 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 now it just shows Invalid file I really don't think you put that script on TOP OF EVERYTHING! Put it on top of your script, first line on the page else { echo "Invalid file"; } you put it in the if statement. Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464370 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 here is where I put it, I really only know basic PHP desperate to get this upload script working <?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it echo $_FILES['file']['type']; if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("./uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464375 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 here is where I put it, I really only know basic PHP desperate to get this upload script working <?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it echo $_FILES['file']['type']; if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("./uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> I told you <?php echo $_FILES['file']['type']; ?> try ]<?php echo $_FILES['file']['type']; ?><?php $file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it echo $_FILES['file']['type']; if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("./uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464379 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 OK I now have a new error application/octet-streamapplication/octet-streamInvalid file Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464386 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 OK I now have a new error application/octet-streamapplication/octet-streamInvalid file Thats the file type, your not uploading an image your uploading a EXE or something else thats not an image. Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464403 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 now I am confused, all I want to do is get this upload script to work the developer says to use your own upload.php but as I can't get this to work maybe we could tweak his version ??? <? $result = array(); if (!headers_sent() && isset($_FILES['image_file']) && ($log = fopen('./upload.log', 'a') ) ) { $file = $_FILES['image_file']['tmp_name']; $error = false; $size = false; if (!is_uploaded_file($file) || ($_FILES['image_file']['size'] > 2 * 1024 * 1024) ) { $error = 'Please upload only files smaller than 2Mb!'; } if (!$error && !($size = @getimagesize($file))) { $error = 'Please upload only images, no other files are supported.'; } if (!$error && !in_array($size[2], array(1, 2, 3, 7, ) ) { $error = 'Please upload only images of type JPEG.'; } if (!$error && ($size[0] < 25) || ($size[1] < 25)) { $error = 'Please upload an image bigger than 25px.'; } fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . ": {$_FILES[image_file][name]} - {$_FILES[image_file][size]} byte \n" ); fclose($log); if ($error) { $result['result'] = 'failed'; $result['error'] = $error; } else { $result['result'] = 'success'; $result['size'] = "Uploaded an image ({$size['mime']}) with {$size[0]}px/{$size[1]}px."; } } else { $result['result'] = 'error'; $result['error'] = 'Missing file or internal error!'; } if (!headers_sent()) { header('Content-type: application/json'); } echo json_encode($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464410 Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 You are trying to upload a non-image file, which doesnt comply with "image/png"..etc Try uploading a GIF image. Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464411 Share on other sites More sharing options...
amwd07 Posted February 11, 2008 Author Share Posted February 11, 2008 I think I will have to give this one up and get back on to the developer Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464418 Share on other sites More sharing options...
amwd07 Posted February 12, 2008 Author Share Posted February 12, 2008 Thanks for everyones help with this finally got it working <?php $uploaddir = '/usr/home/..................../'; // hidden for security reasons $uploadfile = $uploaddir . basename($_FILES['image_file']['name']); if (move_uploaded_file($_FILES['image_file']['tmp_name'], $uploadfile)) { echo "File Uploaded"; } else { echo "Upload Failed!"; } ?> I tried to add the basic validation to this and the upload now fails, anyone any idea's ??? <?php $file_types = array("image/png","image/jpeg","image/gif"); if ((in_array($_FILES["image_file"]["type"],$file_types))&&($_FILES["image_file"]["size"] > 20000)) { $uploaddir = '/usr/home/virtuals/web/comedinewithus/admin/uploads/'; $uploadfile = $uploaddir . basename($_FILES["image_file"]["name"]); if (move_uploaded_file($_FILES["image_file"]["tmp_name"], $uploadfile)) { echo "File Uploaded"; } } else { echo "Upload Failed!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464855 Share on other sites More sharing options...
phpSensei Posted February 12, 2008 Share Posted February 12, 2008 Its becuase of ))&&($_FILES["image_file"]["size"] > 20000 Your saying the file HAS TO BE more than 20000 bytes. Try this ))&&($_FILES["image_file"]["size"] < 20000 Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-465244 Share on other sites More sharing options...
amwd07 Posted February 12, 2008 Author Share Posted February 12, 2008 I now have the following and the upload still fails <?php $file_types = array("image/png","image/jpeg","image/gif"); if ((in_array($_FILES["image_file"]["type"],$file_types))&&($_FILES["image_file"]["size"] < 20000)) { $uploaddir = '/usr/home/virtuals/web/comedinewithus/admin/uploads/'; $uploadfile = $uploaddir . basename($_FILES["image_file"]["name"]); if (move_uploaded_file($_FILES["image_file"]["tmp_name"], $uploadfile)) { echo "File Uploaded"; } } else { echo "Upload Failed!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-465284 Share on other sites More sharing options...
amwd07 Posted February 12, 2008 Author Share Posted February 12, 2008 is there maybe soemthing wrong with using brakets here? Quote Link to comment https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-465370 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.