Php upload file script help

Reply

Join Date: Mar 2009
Posts: 8
Reputation: 1baxter1 is an unknown quantity at this point 
Solved Threads: 0
1baxter1 1baxter1 is offline Offline
Newbie Poster

Php upload file script help

 
0
  #1
Mar 24th, 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!

  1.  
  2. <?php
  3. require 'functions.php';
  4. require 'common.php';
  5.  
  6.  
  7. if(isset($_FILES['fupload'])) {
  8.  
  9. $imagedir = 'img/photo/';
  10. $filename = addslashes($_FILES['fupload']['name']);
  11. $source = $_FILES['fupload']['tmp_name'];
  12. $target = $imagedir . $filename;
  13. $description = addslashes($_POST['description']);
  14. $category = addslashes($_POST['category']);
  15. $title = addslashes($_POST['title']);
  16. $path = $filename;
  17. $thumb = $filename;
  18.  
  19.  
  20. // Validates the form input
  21.  
  22. if(strlen($_POST['description']) < 4)
  23. $error['description'] = '<p class="alert">Please enter a description for your photo. </p>';
  24.  
  25. if(strlen($_POST['title']) < 1)
  26. $error['title'] = '<p class="alert">Please enter a title for your photo. </p>';
  27.  
  28. if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename))
  29. $error['no_file'] = '<p class="alert">Select a image to upload</p>';
  30.  
  31. if(!$error) {
  32. move_uploaded_file($source, $target);
  33.  
  34. $q = "INSERT INTO photo (title, description, source, thumb, category) VALUES('$title', '$description', '$path', '$thumb', '$category')";
  35. $result = $mysqli->query($q) or die(mysqli_error($mysqli));
  36.  
  37. if($result) {
  38. echo "Success! Your file has been uploaded";
  39. }
  40.  
  41. } // end preg_match
  42. }
  43.  
  44. ?>
  45. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  46. <html>
  47.  
  48. <head>
  49. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  50. <link rel="stylesheet" href="css/default.css" />
  51. <title>My Photos</title>
  52. </head>
  53.  
  54. <body>
  55. <h1>My Photos</h1>
  56. <ul><?php getPhotos(); ?></ul>
  57.  
  58. <h1>Upload a Photo</h1>
  59. <form enctype="multipart/form-data" method="post" action="admin.php">
  60. <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
  61. <p><input type="file" name="fupload" /></p>
  62.  
  63. <p><label for="description">Enter a Description: </label> </p>
  64. <p> <textarea rows="6" cols="50" id="description" name="description"></textarea></p>
  65.  
  66. Enter a title: <input type="text" name="title" size="25" id="title" /><br/>
  67.  
  68. Please choose a category:
  69. <select name="category">
  70. <option value="">Select...</option>
  71. <option value="sports">Sports</option>
  72. <option value="london">London</option>
  73. <option value="macro">Macro</option>
  74. <option value="landscapes">Landscapes</option>
  75. <option value="local">Local</option>
  76. </select>
  77.  
  78. <p><input type="submit" value="Upload Photo" name="submit" /></p>
  79. </form>
  80.  
  81. <?php
  82. if ($error['no_file']) echo $error['no_file'];
  83. if ($error['description']) echo $error['description'];
  84. if ($error['title']) echo $error['title'];
  85. ?>
  86.  
  87. <br />
  88.  
  89. </body>
  90. </html>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: Php upload file script help

 
0
  #2
Mar 25th, 2009
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.
  1. $imagedir = '/home/username/html_public/ img/photo/';
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 8
Reputation: 1baxter1 is an unknown quantity at this point 
Solved Threads: 0
1baxter1 1baxter1 is offline Offline
Newbie Poster

Re: Php upload file script help

 
0
  #3
Mar 25th, 2009
the target is fine ive confrmied this although the error seems to be lying with the $source variable, when i use this command

  1. 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Php upload file script help

 
0
  #4
Mar 26th, 2009
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*
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 8
Reputation: 1baxter1 is an unknown quantity at this point 
Solved Threads: 0
1baxter1 1baxter1 is offline Offline
Newbie Poster

Re: Php upload file script help

 
0
  #5
Mar 26th, 2009
So file size is the issue, strange because in the form i set the max filesize to 300000, just for testing purposes and the file im uplaoding is only 35k, i also removed the max filesize feild from the form but still the same error. any ideas
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Php upload file script help

 
0
  #6
Mar 27th, 2009
Try changing upload_max_filesize in php.ini.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Php upload file script help

 
0
  #7
Mar 27th, 2009
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.
  1. 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.
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 8
Reputation: 1baxter1 is an unknown quantity at this point 
Solved Threads: 0
1baxter1 1baxter1 is offline Offline
Newbie Poster

Re: Php upload file script help

 
0
  #8
Mar 27th, 2009
ok il try that soon i set all the permissions up to 777. i appreciate the help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC