Jump to content

File Upload Issues!


twilitegxa

Recommended Posts

I am trying to write this php code that is a form that allows the user to upload images along with a few other text fields. I keep getting this error when trying to upload the file to the server:

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpiPdn6u' to 'http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg' in /home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45

 

 

I have the code set up to tell me where the file is supposed to be uploaded, so it appears to upload kind of, but this error message and checking the actual folder on my server proves it doesn't get uploaded to it. I have had a code like this set up before and it worked, I just cannot find my files at the moment. Here is the code:

 

the form:


<form id="jewelry" name="jewelry" method="post" action="http://webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php" enctype="multipart/form-data">
<table id="jewelry" name="jewelry">
<tr>
<td>Cut:</td>
<td><input type="text" id="cut" name="cut" /></td>
</tr>
<tr>
<td>Color:</td>
<td><input type="text" id="color" name="color" /></td>
</tr>
<tr>
<tr>
<td>Carats:</td>
<td><input type="text" id="carats" name="carats" /></td>
</tr>
<tr>
<td>Clarity:</td>
<td><input type="text" id="clarity" name="clarity" /></td>
</tr>
<tr>
<td>Size Of Ring:</td>
<td><input type="text" id="size" name="size" /></td>
</tr>
<tr>
<td>Type Of Gold:</td>
<td><input type="text" id="type" name="type" /></td>
</tr>
<tr>
<td>Other Diamonds:</td>
<td><input type="text" id="other" name="other" /></td>
</tr>
<tr>
<td>Total Carats:</td>
<td><input type="text" id="total" name="total" /></td>
</tr>
<tr>
<td>Certificate Type:</td>
<td><input type="text" id="certificate" name="certificate" /></td>
</tr>
<tr>
<td>Appraisal Value:</td>
<td><input type="text" id="value" name="value" /></td>
</tr>
<tr>
<td>Upload Image:</td>
<td><input type="file" id="file" name="file" /></td>
</tr>
<td colspan="2"><input type="submit" id="submit" name="submit" value="Submit" />
<input type="reset" id="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form>

 

 

the page that inserts it:


<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');


$dbname = 'database';
mysql_select_db($dbname);


$cut = $_POST['cut'];
$color = $_POST['color'];
$carats = $_POST['carats'];
$clarity = $_POST['clarity'];
$size = $_POST['size'];
$type = $_POST['type'];
$other = $_POST['other'];
$total = $_POST['total'];
$certificate = $_POST['certificate'];
$value = $_POST['value'];


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  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("http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
     $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')";
$query_res = mysql_query($query) or die(mysql_error());
      }
    }
  }
else
  {
  echo "Invalid file";
  }
      
    






?>

 

 

Can anyone help me figure out how to get the image uploaded and saved into the upload folder on the server? Also, the filepath is not getting inserted into the table either for some reason, and not sure why. Please, can anyone help?

Link to comment
Share on other sites

If you run this script from the root of your domain (webdesignsbyliz.com) the code should look like this:

 

 if (file_exists("wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
     $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')";
$query_res = mysql_query($query) or die(mysql_error());
      }

 

You should be able to use relative paths. Let me know how this works out for you.

 

 

Link to comment
Share on other sites

Your code produced these two errors:

 

 

Warning: move_uploaded_file(/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdaKdwL' to '/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg' in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45
Stored in: http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg

What am I doing wrong now? I have:

 

 


<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');


$dbname = 'database';
mysql_select_db($dbname);


$cut = $_POST['cut'];
$color = $_POST['color'];
$carats = $_POST['carats'];
$clarity = $_POST['clarity'];
$size = $_POST['size'];
$type = $_POST['type'];
$other = $_POST['other'];
$total = $_POST['total'];
$certificate = $_POST['certificate'];
$value = $_POST['value'];


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  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("/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
     $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')";
$query_res = mysql_query($query) or die(mysql_error());
      }
    }
  }
else
  {
  echo "Invalid file";
  }
      
    






?>

Link to comment
Share on other sites

I checked your domain and i see the Wordpress is not located in the root of the domain, try this:

Replace "wdbl_wordpress/wp-content/themes/twentyten_2/upload/" with "wp-content/themes/twentyten_2/upload/".

 

if (file_exists("wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
     $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')";
$query_res = mysql_query($query) or die(mysql_error());
      }

 

Also make sure the `upload` folder has writing acces (777).

 

Link to comment
Share on other sites

Still getting the same errors pretty much :-(

 

 

Warning: move_uploaded_file(wp-content/themes/twentyten_2/upload/dd.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqs2yhv' to 'wp-content/themes/twentyten_2/upload/dd.jpg' in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45
Stored in: http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg

I can't remember what I had to do differently before when I tried this very same thing. The only difference was it wasn't on a Wordpress installation, but I wouldn't think that would make a difference, so what else could it be?

 

And yes, I have made sure the permissions were set :-)

Link to comment
Share on other sites

The problem is I can't figure out where is the script running from, I think this is the path of the script:

/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php

 

If you could give me a link of the page where you use this upload script would be very helpful.

Meanwhile try:

 

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: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
     $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"];
     
      $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')";
$query_res = mysql_query($query) or die(mysql_error());
      }

 

 

Link to comment
Share on other sites

The page is here:

 

 

http://webdesignsbyliz.com/wdbl_wordpress/test-page/

 

 

I should have posted this in the beginning, but I completely forgot until now. I hope this helps you see what I am doing wrong. I know it's probably something so simple and something so stupid I am missing! LOL Thank you for all your help!

 

 

BUT...whatever you just told em to do worked! Thank you soooooo much!!!! I'm going to look over it now and try to see what the heck I was doing wrong!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.