| | |
Php upload file script help
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 8
Reputation:
Solved Threads: 0
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 Syntax (Toggle Plain Text)
<?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>
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
Check the file path,also i had the same problem.
but latter on found out it the file path.
it should be something like this.
but latter on found out it the file path.
it should be something like this.
PHP Syntax (Toggle Plain Text)
$imagedir = '/home/username/html_public/ img/photo/';
•
•
Join Date: Mar 2009
Posts: 8
Reputation:
Solved Threads: 0
the target is fine ive confrmied this although the error seems to be lying with the $source variable, when i use this command
i ge the following message
Array ( [name] => Capture.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 )
Aslo if i try and output the $source variable nothing is displayed
thanks
PHP Syntax (Toggle Plain Text)
print_r($_FILES['fupload']);
i ge the following message
Array ( [name] => Capture.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 )
Aslo if i try and output the $source variable nothing is displayed
thanks
http://in2.php.net/manual/en/feature...oad.errors.php Check the reason for the error code 2.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Usually you cannot change the ini file settings on the servers.
But If you want to change the upload_max_filesize, better use the ini_set function.
Using this function you can set the php.ini files values.
e.g.
The above will set the upload filesize for your website to 1 MB.
And related to your issue, please also do check for the permissions on the server for the particular folder where you will be storing your images. The permission should be everyone write, so as any user on your site can upload the images to that folder.
But If you want to change the upload_max_filesize, better use the ini_set function.
Using this function you can set the php.ini files values.
e.g.
php Syntax (Toggle Plain Text)
ini_set("upload_max_filesize",1024768);
The above will set the upload filesize for your website to 1 MB.
And related to your issue, please also do check for the permissions on the server for the particular folder where you will be storing your images. The permission should be everyone write, so as any user on your site can upload the images to that folder.
![]() |
Similar Threads
- Cant upload mp3's with this script? (PHP)
- Sending pic attachments via PHP form (PHP)
- Upload file without User Interaction (PHP)
- Please help!!! Upload script.. (PHP)
- php error HELP!!! (PHP)
- Upload/Download Script... with compression? (PHP)
- Need help with directory displayer code (PHP)
- Apache on linux OS, running PHP scripts (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: Displaying results retrieved into columns
- Next Thread: Get the coorect answer from each question (checkboxes) and compare
| Thread Tools | Search this Thread |
ajax apache api array basic beginner binary body broken cakephp checkbox class cms code cookies cron curl database date date/time display domain dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert interactive ip javascript job joomla js limit link login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop outofmemmory paging parse paypal pdf php procedure query radio ram random regex remote return script search server sessions source space sql stored subdomain syntax system table tutorial unicode update upload url validation validator variable video web webapplications websitecontactform xml youtube






