Jump to content

Recommended Posts

In the code below, the error report I keep getting specfies an issue with ($newname = base64_encode(file_get_contents("./upload/$newname"));) this line of code, you will find it below aswell.

 

I'm trying to upload an image to a folder called "upload".

 

Here is the error report:

Warning: file_get_contents(/upload/image_4c06ab5811896.jpg) [function.file-get-contents]: failed to open stream: No such file or directory in /mnt/w0712/d16/s01/b02c73a9/www/lifelikemedia.ca/wtt/crm/struggle_add_admin.php  on line 69

 

It seems to be a directory or file that is not being seen or not even there. I checked the "upload" folder for which I created and the permissions are set to "777", so full access is allowed. The directory that my page is in is /crm/ and my upload folder is located in /crm/upload/ I checked to make sure there were no spelling issues or case-sensitive issues.

 

Don't make any sense to me.... Can anyone else brighten my day?

 

if ($_REQUEST[completed] == 1) {
$newname = uniqid("image_").".jpg";

// Get the details of the image
list($size, $width, $height, $type, $html_string, $mime) = getimagesize($_FILES['imagefile']['tmp_name']);

move_uploaded_file($_FILES['imagefile']['tmp_name'],"./upload/$newname");

$tmpName = $_FILES['userfile']['tmp_name'];

  if(isset($_POST['submit']))

  {

  $newname = base64_encode(file_get_contents("./upload/$newname"));

      $fname = mysql_real_escape_string(stripslashes($_POST['fname']));
  
  $lname = mysql_real_escape_string(stripslashes($_POST['lname']));
  
  $phone = mysql_real_escape_string(stripslashes($_POST['phone']));
  
  $phone_msg = mysql_real_escape_string(stripslashes($_POST['phone_msg']));

      $rname = mysql_real_escape_string(stripslashes($_POST['rname']));
  
  $location = mysql_real_escape_string(stripslashes($_POST['location']));
  
  $notes = mysql_real_escape_string(stripslashes($_POST['notes']));
  
  $ship_date = mysql_real_escape_string(stripslashes($_POST['ship_date']));

Link to comment
https://forums.phpfreaks.com/topic/203673-image-upload-no-such-file-or-directory/
Share on other sites

If I am understanding correctly, you have a script that uploads an image file.  Once the image has been uploaded, the code snippet you have supplied is then run to move the file to the permanent location and rename it?

 

The error you have there is that the file does not exist in the location given.  Can you confirm that the file has actually been uploaded?  Also, after running move_uploaded_file, can you confirm that the file actually got moved?  E.g. can you see the file in the location that it has moved to before renaming it? 

 

I may be wrong, but to me it doesn't look like the problem is with your $newname = base64_encode... line rather more that your file upload as failed somewhere (either the upload or moving from the temp dir to the permanent one), but of course the error occurs when you try to call the file as it is not there... Hope this helps a little.  Sorry it's not very conclusive.

The warning you have posted:

Warning: file_get_contents(/upload/image_4c06ab5811896.jpg) [function.file-get-contents]:

 

has nothing to do with move_uploaded_file.  You need to look around line 69, or just post your entire script.

I see file_get_contents now.

 

Which makes me either crosseyed, tired, or stupid (probably a combo of all 3).

 

The file doesn't exist.  Did you check to see if it arrived in the directory you pointed it to?

 

Why do you want to save the image to a directory if you are going to base64 encode it into your database?

Reply to jcbones:

No file is created, however the I also have text accompanied by the image upload and that passed through okay. base64 is all I am familiar with, do you have another option? Thank you :)

 

Reply to jd307:

The file has not been physically uploaded, only the text accompanied in the POST. No file anywhere to be found... Anything to help me fix this issue, thank you :)

I would save the image path to the database, instead of the image itself. 

 

But, if you are going to store the image to the database, why do you need to store it to the server.  Just encode it from the $_FILES['image']['tmp_name'].

 

Is your form enctype set?

<form action="" method="post" enctype="multipart/form-data">

 

This would be the only reason I could think that the form would submit text and not files.

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.