lbaxterl Posted March 24, 2009 Share Posted March 24, 2009 Hi Ive wrote a upload script for a photo website im making and ive cam across a unusual problem. The script inserts all the values into the databse correctly and displays "file upload successfull" but the photos are not copying onto the server. any help will be appreciated, thank you! <?php require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $imagedir = 'img/photo/'; $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $target = $imagedir . $filename; $description = addslashes($_POST['description']); $category = addslashes($_POST['category']); $title = addslashes($_POST['title']); $path = $filename; $thumb = $filename; // Validates the form input if(strlen($_POST['description']) < 4) $error['description'] = '<p class="alert">Please enter a description for your photo. </p>'; if(strlen($_POST['title']) < 1) $error['title'] = '<p class="alert">Please enter a title for your photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '<p class="alert">Select a image to upload</p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT INTO photo (title, description, source, thumb, category) VALUES('$title', '$description', '$path', '$thumb', '$category')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Success! Your file has been uploaded"; } } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> </p> <p> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> Enter a title: <input type="text" name="title" size="25" id="title" /><br/> Please choose a category: <select name="category"> <option value="">Select...</option> <option value="sports">Sports</option> <option value="london">London</option> <option value="macro">Macro</option> <option value="landscapes">Landscapes</option> <option value="local">Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <?php if ($error['no_file']) echo $error['no_file']; if ($error['description']) echo $error['description']; if ($error['title']) echo $error['title']; ?> <br /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/ Share on other sites More sharing options...
Ayon Posted March 24, 2009 Share Posted March 24, 2009 first off... use the CODE tag! second.. provide some more info about where the error occurs etc.. dont expect any helping answers with a topic like this Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793154 Share on other sites More sharing options...
lbaxterl Posted March 24, 2009 Author Share Posted March 24, 2009 sorry i didnt copy/paste it properly, there is no error, the file just doesn't appear in the img folder Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793160 Share on other sites More sharing options...
Ayon Posted March 24, 2009 Share Posted March 24, 2009 if you echo $source & $target.. what's the result? Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793164 Share on other sites More sharing options...
kickstart Posted March 24, 2009 Share Posted March 24, 2009 Hi Would agree with the above about ecjoing $source and $target. However move_uploaded_file returns false if it cannot move the file. Try:- if (move_uploaded_file($source, $target) === false) { echo "File move failed"; } All the best Keith Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793170 Share on other sites More sharing options...
lbaxterl Posted March 24, 2009 Author Share Posted March 24, 2009 sorry i didnt copy/paste it properly, there is no error, the file just doesn't appear in the img folder Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793177 Share on other sites More sharing options...
kickstart Posted March 24, 2009 Share Posted March 24, 2009 Hi What is the file name? Likely to be corrupted as a file name by addslashes? All the best Keith Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793181 Share on other sites More sharing options...
Ayon Posted March 24, 2009 Share Posted March 24, 2009 Hi What is the file name? Likely to be corrupted as a file name by addslashes? All the best Keith you read my mind on that one... Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793186 Share on other sites More sharing options...
lbaxterl Posted March 24, 2009 Author Share Posted March 24, 2009 the file im testing on is "capture.jpg" im abit of a php n00b sorry should i remove the addslashes? Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793189 Share on other sites More sharing options...
Ayon Posted March 24, 2009 Share Posted March 24, 2009 try Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793194 Share on other sites More sharing options...
lbaxterl Posted March 24, 2009 Author Share Posted March 24, 2009 think we may have found the problem i echos the $source and $target and it seems like the source is empty, the message reads "Success! Your file has been uploaded . . img/photo/Capture.jpg " heres the code <?php require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $imagedir = 'img/photo/'; $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $target = $imagedir . $filename; $description = addslashes($_POST['description']); $category = addslashes($_POST['category']); $title = addslashes($_POST['title']); $path = $filename; $thumb = $filename; // Validates the form input if(strlen($_POST['description']) < 4) $error['description'] = '<p class="alert">Please enter a description for your photo. </p>'; if(strlen($_POST['title']) < 1) $error['title'] = '<p class="alert">Please enter a title for your photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '<p class="alert">Select a image to upload</p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT INTO photo (title, description, source, thumb, category) VALUES('$title', '$description', '$path', '$thumb', '$category')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Success! Your file has been uploaded . $source . $target"; } } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> </p> <p> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> Enter a title: <input type="text" name="title" size="25" id="title" /><br/> Please choose a category: <select name="category"> <option value="">Select...</option> <option value="sports">Sports</option> <option value="london">London</option> <option value="macro">Macro</option> <option value="landscapes">Landscapes</option> <option value="local">Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <?php if ($error['no_file']) echo $error['no_file']; if ($error['description']) echo $error['description']; if ($error['title']) echo $error['title']; ?> <br /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793204 Share on other sites More sharing options...
lbaxterl Posted March 24, 2009 Author Share Posted March 24, 2009 removed the add slashes, it didnt work, the info is still entered into the database though! thanks for the help guys Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793206 Share on other sites More sharing options...
Ayon Posted March 24, 2009 Share Posted March 24, 2009 so what you're saying is that $source and $target returns nothing? if so you need to check the $_FILES... add this line to your code print_r($_FILES['fupload']); Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793208 Share on other sites More sharing options...
lbaxterl Posted March 25, 2009 Author Share Posted March 25, 2009 the target returns img/photo/capture.jpg. the source returns nothing Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793216 Share on other sites More sharing options...
lbaxterl Posted March 25, 2009 Author Share Posted March 25, 2009 i think were getting somewhere when insert the code you gave: print_r($_FILES['fupload']); i get this message: Array ( [name] => Capture.jpg [type] => [tmp_name] => [error] => 2 => 0 ) Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793220 Share on other sites More sharing options...
lbaxterl Posted March 25, 2009 Author Share Posted March 25, 2009 ok the servers back up! now its outputting these errors but echoing the $source and $target: Warning: move_uploaded_file(img/photo/n656985202_6030227_7816996.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /web/users/e5034824/Test/admin.php on line 31 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpij8aCM' to 'img/photo/n656985202_6030227_7816996.jpg' in /web/users/e5034824/Test/admin.php on line 31 Link to comment https://forums.phpfreaks.com/topic/150972-php-upload-file-script-not-copying-photo-please-help-deadlines-tommorow/#findComment-793257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.