Jump to content

PHP Upload Script Help


eatfishy

Recommended Posts

Below is a script that I have to upload files onto my website. The message shows that image is uploaded, but when I check folder, I don't see any images in there. I am not getting any error messages either. Please help me. Thanks.

 

 

<?php

include("Session.php");

/*

***************************************************************************************

 

***************************************************************************************

*/

//prepare a form similiar to this and have it call the below file

//echo '<form action="image_upload.php" method="post" enctype="multipart/form-data">';

//echo 'Click the Browse button to find the file you wish to upload';

//echo '<input type="file" name="imagefile">';

//echo '<input type="submit" name="upload" value="upload">';

//echo '</form>';

/**************************************************************************************

***************************************************************************************

***************************************************************************************

***        <input type="file" name="imagefile">                                          ***

***        with the above tag declared in the calling form        ***

***        the variable name is $imagefile and the available properties are ***

***        $imagefile :name of the file as stored on the temporary server directory ***

***        $imagefile_name :filename.extension of the file as on the users machine ***

***        $imagefile_size        :size in bytes of the file ***

***        $imagefile_type        :the type of file image/gif image/jpg text/html etc.... ***

*** ***

***************************************************************************************

***************************************************************************************

*/

//change these values to suit your site

$ftp_user_name='username';

$ftp_user_pass='password';

 

$ftp_server='ftpserver;

$ftp_dir='ftpdirectory';

//$web_location is needed for the file_exists function, the directories used by FTP

//are not visible to it will will always return not found.

$web_dir='websitedirectory';

$web_location=$web_dir.$imagefile_name;

 

//build a fully qualified (FTP) path name where the file will reside

$destination_file=$ftp_dir.$imagefile_name;

 

// connect, login, and transfer the file

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$upload = ftp_put($conn_id, $destination_file, $imagefile, FTP_ASCII);

 

//use ftp_site to change mode of the file

//this will allow it be visible by the world,

$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);

// close the FTP stream

ftp_close($conn_id);

 

//verify file was written

if (file_exists($web_location))

        {

        echo "File was uploaded as $web_location"."<br>";

        echo error_reporting(E_ALL);

        }

else

        {

        echo "Could not create $web_location";

        }

//end if

 

?>

Link to comment
Share on other sites

Well, you should start by reading the manual: http://us.php.net/manual/en/features.file-upload.post-method.php

 

Next, I don't see this defined anywhere:

$web_location=$web_dir.$imagefile_name;

You don't specify anywhere what $imagefile_name is so it is just checking if the directory exists more than likely.

When you do assign a value to $imagefile_name, you need a slash and it would look something like this:

$web_location="$web_dir/$imagefile_name";

 

That should at least get you to the point where you'll start getting error message that will show you what to fix next.

 

Handy PHP

Link to comment
Share on other sites

Thanks for the fast response. I have read the PHP manual, but it wasn't too clear to me on subject about uploading with login. I figured out what the problem was, which really is the configuration of the php.ini setting. I need to change the temp directory in the php.ini and also include that temp directory in my ftp directory path. Hope this helps others as well.

 

Express who you are in www.blogoberry.com

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.