lewis987 Posted May 8, 2007 Share Posted May 8, 2007 ok i have an upload script: <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 2000000)) { 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("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> however, when i test it, it fails straight away, anyone got a remedy? thanks! Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/ Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 Post the form also Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248006 Share on other sites More sharing options...
lewis987 Posted May 8, 2007 Author Share Posted May 8, 2007 ok heres the form: <form action="upload.php" method="get" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248016 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 chmod("upload", 777); move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248018 Share on other sites More sharing options...
igor berger Posted May 8, 2007 Share Posted May 8, 2007 CHMOD 766 for upload dir no no no 777 is securety risk, will allow to execute the file!!!! Make sure the upload is above the dir you running the script in, if not use absolute path! /home/usernamer/etc... or you have your own server maybe C:\\ not sure Use enviromental variable to look up your documer root! $Server['document_root'] check syntax www.php.net Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248022 Share on other sites More sharing options...
lewis987 Posted May 8, 2007 Author Share Posted May 8, 2007 that makes no difference, i get invalid file when i run the script, like its not processing the upload.php file fully Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248032 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 if(in_array($_FILES["file"]["type"],array('image/pjpeg','image/gif')) and ($_FILES["file"]["size"] < 2000000)){ } Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248043 Share on other sites More sharing options...
lewis987 Posted May 8, 2007 Author Share Posted May 8, 2007 still no luck Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248129 Share on other sites More sharing options...
igor berger Posted May 8, 2007 Share Posted May 8, 2007 Why don't you post the url to your no luck. Maybe one of us can pick up the error! Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248147 Share on other sites More sharing options...
lewis987 Posted May 8, 2007 Author Share Posted May 8, 2007 ok, it will be on between 6PM and 9PM (GMT) tomorrow Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248579 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 Two issues... 1) You needed brackets around your image type condition.... (gif || jpeg) && filesize.... 2) You had pjpeg instead of jpeg <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")) && ($_FILES["file"]["size"] < 2000000)) { 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("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248599 Share on other sites More sharing options...
jitesh Posted May 9, 2007 Share Posted May 9, 2007 <?php echo "<pre>"; print_r($_FILES['file']); // Print this and post the o/p here if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { .......... .......... ......... ?> Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248713 Share on other sites More sharing options...
lewis987 Posted May 9, 2007 Author Share Posted May 9, 2007 infact, i forgot opera store cache, i needed to empty it o load up the new page, it works now! thanks a tonne! Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-249163 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 9, 2007 Share Posted May 9, 2007 I uploaded a small jpeg and it worked.... Upload: throw_away_religion.jpg Type: image/jpeg Size: 3.8388671875 Kb Temp file: C:\xampp2\tmp\php52.tmp Stored in: upload/throw_away_religion.jpg Try a gif next...see if that works... Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-249184 Share on other sites More sharing options...
igor berger Posted May 9, 2007 Share Posted May 9, 2007 Glad to see that you got it to work. But I would set CHMOD to 766 it should work also. With CHMOD 777 public can execute a program. So if it works with 766 do it, but if you need 777 then you have no choice. But 777 is secyrety risk. Link to comment https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-249250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.