Jump to content

[SOLVED] Uploading on Localhost


mattal999

Recommended Posts

Hi,

 

Basically, i'm trying to upload a file, say 1.jpg, to a folder using PHP.

 

I am using this:

 

<?php
function is_uploaded_file2($filename) 
{
   if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
       $tmp_file = dirname(tempnam('', ''));
   }
   $tmp_file .= '/' . basename($filename);
   return (ereg_replace('/+', '/', $tmp_file) == $filename);
}
if(isset($_POST))
{
if(is_uploaded_file2($_FILES['mp3']['tmp_name']))
{
if($_FILES['mp3']['type'] == 'audio/mpeg')
{
$files = $_FILES['mp3'];
$tmpname = $files['tmp_name'];
$name = $files['name'];
if(move_uploaded_file($tmpname, 'upload/'.$name))
{

CLIPPED

 

and this works fine on my website when uploaded via FTP to my proper website, but not on localhost.

 

It fails on is_uploaded_file2()

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

I don't get an error, this runs:

 

echo is_uploaded_file2($_FILES['mp3']['tmp_name']);
?>
<script>
window.parent.document.getElementById("mp3upload").style.display='block';
window.parent.document.getElementById("progress").style.display='none';
window.parent.document.getElementById("donedev").style.display='block';
window.parent.document.getElementById("donedev").innerHTML='The file could not be uploaded!';
</script>

 

And i don't get anything where i put echo "the function".

 

I'm running PHP4

Link to comment
Share on other sites

What do you mean by 'it fails on is_uploaded_file2()' ? Do you get any error messages? What actually happens?

 

On a sidenote, this isn't a valid way of checking if the form's been submitted:

 

if(isset($_POST))

 

That will always return true, since the superglobal arrays are always defined, regardless of if there's anything in them or not. Try using:

 

if(count($_POST) > 0)

 

Oh, and it'd really help if you indented your code properly.

Link to comment
Share on other sites

As you are running this on a local install edit your php.ini and make sure erroir_reporting is set to E_ALL and display_errors is set to On.

 

Make sure you restart your HTTP server (eg Apache, IIS etc) after modifying the php.ini. If there is any errors in your code they should be displayed during runtime.

 

You may want to post your code in full too.

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.