marcha Posted May 25, 2009 Share Posted May 25, 2009 Hello there. Could you help me out with one thing please. This is a simple example with img upload which works fine just by itself. But when I add more input fields to form and then submit the form all the values are inserted into database but the picture isn't uploaded to specified directory. what am I missing ??? form: <form enctype="multipart/form-data" action="uploader.php" method="POST"> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> execute: <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { } else{ echo "Problem uploading file!"; } ?> Link to comment https://forums.phpfreaks.com/topic/159551-solved-image-upload/ Share on other sites More sharing options...
waynew Posted May 25, 2009 Share Posted May 25, 2009 Try this: <?php //firstly - you'll want to make sure that the file is actually after being uploaded //its a security issue if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])){ $target_path = "uploads/"; //is your target path a directory? if(is_dir($target_path){ //I've never needed to use basename() before. $target_path = $target_path.$_FILES['uploadedfile']['name']; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){ echo 'File uploaded to '.$target_path; } else{ echo "Problem uploading file! Check your directories file permissions!"; } } //not a directory else{ echo $target_path." was not found to be a directory."; } } //not an uploaded file else{ echo 'No file uploaded'; } ?> Link to comment https://forums.phpfreaks.com/topic/159551-solved-image-upload/#findComment-841613 Share on other sites More sharing options...
marcha Posted May 25, 2009 Author Share Posted May 25, 2009 thanks waynewex working fine now Link to comment https://forums.phpfreaks.com/topic/159551-solved-image-upload/#findComment-841627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.